import Vue from "vue";
// import { create } from 'core-js/core/object'  onBeforeRouteUpdate
// import {createRouter,createWebHashHistory} from 'vue-router'
// import {createApp} from 'vue'
import Router from 'vue-router'
import viewCollects from '../utils/collects'
// const projectList =()=>import('../view/project/projectList')
// const projectEdit =()=>import('../view/project/projectEdit')
// const projectView = ()=>import('../view/project/projectView')

// const app = createApp()

Vue.use(Router)
// eslint-disable-next-line no-unused-vars
const list = viewCollects()

const router = new Router({
 // const router = [
    //  routes:list,
    routes:[
        {
            path:'/',component:()=> import('../view/main.vue'),meta:{title:'主页'}
        },
        {
            path:'/chat',component:()=> import('../view/collection/chatting.vue'),meta:{title:'公开聊天群'}
        },
        {
            path:'/manage',component:()=>import('../view/manage/index.vue'),meta:{title:'管理系统'}
        },
        // {
        //     path:'/comment',component:()=>import('../view/collection/comment.vue'),meta:{title:'嵌套评论'}
        // },
        {path: '/error404', component: ()=>import('../view/error/404NotFound') ,meta:{title:'无法找到'}},
          {path:'*',redirect: "/404notFound"}
    ]
})
// 路由导航卫视
router.beforeEach((to, from, next) => {
    console.log(to.name,from.name)
    if(to.matched.length === 0 ){
        from.name ? next({
            name:from.name
        }) : next('/error404')
    }
    if(to.meta.title){
        document.title = to.meta.title
    }
    //
    // if(to.name.indexOf('client')!=-1 || to.name.indexOf('manage')!= -1 || to.name.indexOf('order')!= -1
    //     || to.name.indexOf('modify')!= -1 || to.name.indexOf('edit')!= -1 || to.name.indexOf('create')!= -1
    // ) {
    //     var tokenStr = sessionStorage.getItem('state')
    //     if(!tokenStr) {
    //         return next('/login')
    //     }
    // }
    next()
    // router.app.$options.store.commit("changePath",from.name)
})

// const router = createRouter({
//     history:createWebHashHistory(),
//     routes
// })

export default router
